
//-------------------------------    userquery.jsp     -------------------------------------
function removeuser(ele) {
    $.get('../user/delete.do?userId='+ele,function (res) {
        console.log(ele);
        if (res.result){
            $('#tr_'+ele).remove();
        }
    },'json');
}
$(function () {
    //缩写图片
    setImg(100,100);

    //删除的模态框
    $('.deleteuser').click(function () {
        var userId = $(this).attr('deleteuser');
        swal({
                title: "是否删除?",
                text: "你将无法恢复此用户信息!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#73879C",
                confirmButtonText: "确认!",
                cancelButtonText: "取消!",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    console.log(userId);
                    removeuser(userId);
                    swal("删除!", "你已删除此用户 ", "success");
                } else {
                    swal("取消", "你已取消删除 ", "error");
                }
            });
    });

    // 修改密码确认弹窗
    $('.updateuser').click(function () {
        var pass = $(this).attr('updateuser');

        swal({
                title: "你确定重置此密码?",
                text: "你将会重置此密码!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#73879C",
                confirmButtonText: "确定，重置!",
                cancelButtonText: "取消，返回!",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    toUpdateuser(pass);
                    swal("重置!", "你重置了此密码.", "success");
                } else {
                    swal("取消", "你取消了重置此密码", "error");
                }
            });
    });

});

function toUpdateuser(ele) {
    $.get('../user/update.do?userId='+ele,function (res) {
        console.log(ele);

    },'json')
}

function setImg(w, h){
    var imgList = $('.imgs');
    for(var i=0;i<imgList.length;i++){
        if(imgList[i].width>w && imgList[i].height>h){
            imgList[i].width = w;
            imgList[i].heigth = h;
        }
        else if (imgList[i].width>w && imgList[i].height<=h){
            imgList[i].width = w;
        }
        else if(imgList[i].width<=w && imgList[i].height>h){
            imgList[i].heigth = h;
        }
    }
}
//----------------------------------------- userquery.jsp -------------------------------------------


//---------------------------------  orderquery.jsp  -------------------------------------------------------

function removeorder(ele) {
    $.get('../Trdif/delete.do?trdNo='+ele,function (res) {
        if (res.result){
            console.log("ele:  ");
            console.log(ele);
            $('#tr_'+ele).remove();
        }
    },'json');
}
$(function () {

    //删除的模态框
    $('.deleteorder').click(function () {
        var trdno = $(this).attr('deleteorder');
        swal({
                title: "是否删除?",
                text: "你将无法查看此订单!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#73879C",
                confirmButtonText: "确认!",
                cancelButtonText: "取消!",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    removeorder(trdno);
                    swal("删除!", "你已移除此订单 ", "success");
                } else {
                    swal("取消", "你已取消移除 ", "error");
                }
            });
    });
});
function toUpdateorder(ele, trdno) {
    $('#updateModal .modal-content').empty();
    $.get('../after/orderupdate.jsp?trdNo='+trdno,function (res) {
        $('#updateModal .modal-content').append(res);
    })


}
function updatetradeinfo(trdNo) {
    var data = $('#orderupdate').serialize();
    console.log(data);
    $.post('../Trdif/update.do',data, function (res) {
        if (res.result){
            // 手动关闭模态框
            $('#updateModal').modal('hide');
            $('#updateModal .modal-content').empty();
            swal({
                title: "更新结果",
                text: "更新成功"
            },function () {
                location.reload();
            });
        } else {
            swal({
                title: "更新结果",
                text: "更新编号：" + trdNo + " 的订单信息失败！",
                type: "error"
            });
        }
    },'json');
}


//---------------------------------  orderquery.jsp  ------------------------------------------------------



//---------------------------------  updatePassAdmin.jsp  -----------------------------------------------------

$(function () {

    $('.updatapass').click(function () {

        var userid = $('#userid').val();
        var oldPassword = $('#oldPassword').val();
        var password = $('#newPass2').val();

        $.get("../admin/update.do",
            {"userid":userid,"oldPassword":oldPassword,"password":password},
            function (res) {
                console.log(res);
                if (res.result){
                    // 手动关闭模态框
                    swal({
                        title: "修改密码结果",
                        text: "修改成功"
                    },function () {

                        location.href="../after/managerlogin.jsp"

                        /*return "../after/managerlogin.jsp";*/
                    });
                } else {
                    swal({
                        title: "修改密码结果",
                        text: "修改密码失败！",
                        type: "error"
                    });
                }
            },'json');
    });


});

function resetpass(){
    console.log(".fondpass");
    $('.fondpass').empty();
}

$(document).ready(function () {

    $('#newPass1').on('input propertychange',function () {
        var pass1 = $.trim($(this).val());
        var pass2 = $.trim($('#newPass2').val());

        if (pass1==""&&pass2==""){
            $("#msg_pwd").html("<font color='red' class='fondpass'>密码不能为空</font>");
        }
        else if (pass2!=""){
            if (pass1==pass2){
                $('#msg_pwd').html("<font color='green' class='fondpass'>两次密码相同</font>");
                $('.updatapass').attr("disabled",false);
            }else {
                $('#msg_pwd').html("<font color='red' class='fondpass'>两次密码不相同</font>");
                $('.updatapass').attr("disabled",true);
            }
        }
    })

});

$(document).ready(function () {

    $('#newPass2').on('input propertychange',function () {
        var pass1 = $.trim($(this).val());
        var pass2 = $.trim($('#newPass1').val());

        if (pass1==""&&pass2==""){
            $("#msg_pwd").html("<font color='red' class='fondpass'>密码不能为空</font>");
        }
        else if (pass2!=""){
            if (pass1==pass2){
                $('#msg_pwd').html("<font color='green' class='fondpass'>两次密码相同</font>");
                $('.updatapass').attr("disabled",false);
            }else {
                $('#msg_pwd').html("<font color='red' class='fondpass'>两次密码不相同</font>");
                $('.updatapass').attr("disabled",true);
            }
        }
    })

});


/*//修改密码
function updatePassword() {
    //var old = $('#oldPassword').val();
    var new1 = $('#newPass1').val().trim();
    var new2 = $('#newPass2').val().trim();
    if (new1 !== new2) {
        alert("两次密码不一致。")
        return false;
    }else {
        return true;
    }
}*/







//-----------addProduct---------------------
function bigType(){
    var bigCtgr = $('#bigCtgr').val();
    $.ajax({
        type: 'get',
        url: '../Category/queryByBigCtgr.do',
        data: {'bigCtgr': bigCtgr},
        dataType: 'json',
        success: function (res) {
            var littleTypeSelect = $('#ctgrId');
            littleTypeSelect.find("option").remove();
            res.forEach(function (type) {
                var option = new Option(type.ctgrName, type.ctgrId);
                littleTypeSelect.append(option);
            })
        }
    })
}




// ------------------------------  updatePassAdmin.jsp  -----------------------------------------------------